﻿// Gruntfile.js  安装了 eslint之后下面的命令就都在任务运行程序资源管理器中可用了
module.exports = function (grunt) {
    // Project configuration.
    grunt.initConfig({
        clean: ["wwwroot/lib/*", "temp/"],

        // Copy files from TypeScript to wwwroot/lib
        concat: {
            all: {
                src: ['TypeScript/Taste.js', 'TypeScript/Food.js'],
                dest: 'temp/combined.js'
            }
        },

        //
        jshint: {
            files: ['temp/*.js'],
            options: {
                // Enforce JSHint rules
                '-W069': false
            }
        },

        // Minify the combined JavaScript file
        uglify: {
            all: {
                src: ['temp/combined.js'],
                dest: 'wwwroot/lib/combined.min.js'
            }
        },

        // Compile TypeScript files to JavaScript
        ts: {
            default: {
                src: ["TypeScript/*.ts"],
                outDir: "TypeScript",
                options: {
                    target: "es5",
                    sourceMap: true,
                    declaration: false,
                    removeComments: false
                }
            },
            options: {
                rootDir: "TypeScript",
            }
        },

        // Watch for changes in TypeScript files and recompile
        watch: {
            scripts: {
                files: ['TypeScript/*.ts'],
                tasks: ['ts', 'concat', 'jshint', 'uglify'],
                options: {
                    spawn: false,
                },
            },
        }


    });
    // Default task(s).
   
    // Load the plugin that provides the "clean" task.
    grunt.loadNpmTasks('grunt-contrib-clean');

    // Load the plugin that provides the "ts" task.
    grunt.loadNpmTasks('grunt-ts');

    // Load the plugin that provides the "concat" task.
    grunt.loadNpmTasks('grunt-contrib-concat');

    // Load the plugin that provides the "jshint" task.
    grunt.loadNpmTasks('grunt-contrib-jshint');

    // Load the plugin that provides the "uglify" task.
    grunt.loadNpmTasks('grunt-contrib-uglify');

    // Load the plugin that provides the "watch" task.
    grunt.loadNpmTasks('grunt-contrib-watch');
   
    // Register tasks 数组中的任务将按顺序执行 上面的代码也需要按照这个顺序执行
    grunt.registerTask('default', ['clean', 'ts', 'concat', 'jshint', 'uglify']);


};